<template>
  <el-form
    ref="registerForm"
    :rules="registerRules"
    :model="registerForm"
    class="login-form"
    status-icon
    label-width="0">
    <el-form-item prop="name">
      <el-input
        v-model="registerForm.name"
        size="small"
        auto-complete="off"
        placeholder="请输入组织名称">
        <i
          slot="prefix"
          class="iconfont icon-yonghu"/>
      </el-input>
    </el-form-item>
    <el-form-item prop="code">
      <el-input
        v-model="registerForm.code"
        size="small"
        auto-complete="off"
        placeholder="请输入组织编号">
        <i
          slot="prefix"
          class="iconfont icon-bofang"/>
      </el-input>
    </el-form-item>
    <el-form-item prop="logo">
      <el-input
        v-model="registerForm.logo"
        size="small"
        auto-complete="off"
        placeholder="请输入logo">
        <i
          slot="prefix"
          class="iconfont icon-shuzi"/>
      </el-input>
    </el-form-item>
    <el-form-item prop="realName">
      <el-input
        v-model="registerForm.realName"
        size="small"
        auto-complete="off"
        placeholder="请输入姓名">
        <i
          slot="prefix"
          class="iconfont icon-xinshouyindao"/>
      </el-input>
    </el-form-item>
    <el-form-item prop="phone">
      <el-input
        v-model="registerForm.phone"
        size="small"
        auto-complete="off"
        placeholder="请输入手机号">
        <i
          slot="prefix"
          class="iconfont icon-jingpin"/>
      </el-input>
    </el-form-item>
    <el-form-item prop="password">
      <el-input
        v-model="registerForm.password"
        size="small"
        auto-complete="off"
        placeholder="请输入密码">
        <i
          slot="prefix"
          class="iconfont icon-shangpin"/>
      </el-input>
    </el-form-item>
    <el-form-item prop="secondPassword">
      <el-input
        v-model="registerForm.secondPassword"
        size="small"
        auto-complete="off"
        placeholder="再次输入密码">
        <i
          slot="prefix"
          class="iconfont icon-shangpin"/>
      </el-input>
    </el-form-item>
    <el-form-item>
      <el-button style="background-color: #444;
    border-color: #444;"
        type="primary"
        size="small"
        class="login-submit"
        @click.native.prevent="handleRegister">注册
      </el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import { randomLenNum } from '@/util/util'
import { Message } from 'element-ui'

export default {
  name: 'UserRegister',
  props:{
    activeName: {
      type: String,
      default: ''
    },
  },
  data() {
    return {
      registerForm: {
        name: '',
        phone: '',
        realName: '',
        logo: '',
        province: '',
        city: '',
        area: '',
        address: '',
        password: '',
        secondPassword: ''
      },
      checked: false,
      registerRules: {
        name: [
          { required: true, message: '请输入组织名称', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 6, message: '密码长度最少为6位', trigger: 'blur' }
        ],
        code: [
          { required: true, message: '请输入组织简称', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
  },
  mounted() {
  },
  computed: {
  },
  props: [],
  methods: {

    handleRegister() {
      this.$refs.registerForm.validate(valid => {
        if (valid) {
          this.$store.dispatch('Register', this.registerForm).then(() => {
            Message({
              message: "恭喜您，注册成功，请登录",
              type: 'success'
            })
            this.$emit("changeactiveName", "user")
          }).catch(() => {
          })
        }
      })
    }
  }
}
</script>

<style>
</style>
